package com.sanhe.rfmuscle.activity.work;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.menu.app.MyApp;
import com.sanhe.rfmuscle.App;
import com.sanhe.rfmuscle.databinding.ActivityPwd2Binding;

public class Pwd2Activity extends BaseWorkActivity {
    Typeface medium = Typeface.createFromAsset(App.getApp().getAssets(), "HarmonyOS_Sans_Medium.ttf");
    ActivityPwd2Binding binding;


    String from;

    public void setFrom(String str) {
        from = str;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityPwd2Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        binding.back.setOnClickListener(v -> finish());

        binding.title.setTypeface(medium);
        binding.et.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD | InputType.TYPE_CLASS_NUMBER);
        binding.et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && actionId == EditorInfo.IME_ACTION_UNSPECIFIED && event.getAction() == KeyEvent.ACTION_DOWN) || actionId == EditorInfo.IME_ACTION_DONE
                        || (event != null
                        && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event
                        .getAction() == KeyEvent.ACTION_DOWN)) {
                    String text = binding.et.getText().toString();
                    Log.e(TAG, "onEditorAction: " + text);
                    if (fromSetting()) {
                        if (text.equals("158111")) {
                            Intent intent = new Intent(Pwd2Activity.this, SnActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    } else {
                        Toast.makeText(Pwd2Activity.this, "unknown activity", Toast.LENGTH_SHORT).show();
                    }


                    return true;
                }
                return false;
            }
        });

    }

    public boolean fromSetting() {
        Class c = SettingActivity.class;
        if (c == null) {
            return false;
        }
        return c.getSimpleName().equals(from);
    }

    public boolean fromInfo() {
        Class c = InfoActivity.class;
        if (c == null) {
            return false;
        }
        return c.getSimpleName().equals(from);
    }

}
